package entity;

import geometry.Circle;

import java.awt.geom.Point2D;

/**
 * Safe region is a circle
 * 
 * @author xiaohui
 * 
 */
public class MobileRegion extends Circle {
	public Velocity v;
	public int creationTime;
	public int moid;
	public int xlow, xhigh, ylow, yhigh;

	public int[] convertExtent2Grid(int cellLength) {
		return new int[] { xlow / cellLength, xhigh / cellLength,
				ylow / cellLength, yhigh / cellLength };
	}

	public int[] getExtent() {
		return new int[] { xlow, ylow, xhigh, yhigh };
	}

	public double getMaxDist(MobileRegion region){
		return this.getCenterP().distance(region.getCenterP())
		+ this.radius + region.radius;
	}
	
	public double getMinDist(MobileRegion region) {
		double d = this.getCenterP().distance(region.getCenterP())
				- this.radius - region.radius;
		return Math.max(d, 0);
	}

	public MobileRegion(Point2D center, double radius, int moid, Velocity v,
			int creationTime) {
		super(center, radius);
		this.v = v;
		this.moid = moid;
		this.creationTime = creationTime;
		this.updateExtent();
	}

	public String toString() {
		return "SR(" + this.getCenterX() + "," + this.getCenterY() + ","
				+ this.radius + ")";
	}

	public void updateExtent() {
		xlow = (int) Math.max(0, this.getCenterX() - this.radius);
		xhigh = (int) (this.getCenterX() + this.radius);
		ylow = (int) Math.max(0, this.getCenterY() - this.radius);
		yhigh = (int) (this.getCenterY() + this.radius);
	}

}
